/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cse308.entities;

import cse308.GeneralEntity;
import cse308.helper_classes.GeneralTest;
import cse308.helper_classes.MinuteClass;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.Lob;
import javax.persistence.ManyToMany;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author Aaron
 */
@Entity
@Table(catalog = "nchorn", schema = "")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Minute.findAll", query = "SELECT m FROM Minute m"),
    @NamedQuery(name = "Minute.findByDate", query = "SELECT m FROM Minute m WHERE m.date = :date"),
    @NamedQuery(name = "Minute.findByGrp", query = "SELECT m FROM Minute m WHERE m.grp = :grp"),
    @NamedQuery(name = "Minute.findByIdentifier", query = "SELECT m FROM Minute m WHERE m.identifier = :identifier")})
public class Minute implements Serializable, GeneralEntity {
    private static final long serialVersionUID = 1L;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 20)
    @Column(nullable = false, length = 20)
    private String date;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 20)
    @Column(nullable = false, length = 20)
    private String grp;
    @Basic(optional = false)
    @NotNull
    @Lob
    @Column(nullable = false)
    private byte[] minutes;
    @Id
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 20)
    @Column(nullable = false, length = 20)
    private String identifier;
    @JoinTable(name = "minutetodegree", joinColumns = {
        @JoinColumn(name = "minute", referencedColumnName = "identifier", nullable = false)}, inverseJoinColumns = {
        @JoinColumn(name = "degree", referencedColumnName = "identifier", nullable = false)})
    @ManyToMany
    private Collection<Degreeprogram> degreeprogramCollection;

    public Minute() {
        this.degreeprogramCollection = new ArrayList();
    }

    public Minute(String identifier) {
        this.identifier = identifier;
        this.degreeprogramCollection = new ArrayList();
    }

    public Minute(String identifier, String date, String grp, byte[] minutes) {
        this.identifier = identifier;
        this.date = date;
        this.grp = grp;
        this.minutes = minutes;
        this.degreeprogramCollection = new ArrayList();
    }

    public String getDate() {
        return date;
    }

    public void setDate(String date) {
        this.date = date;
    }

    public String getGrp() {
        return grp;
    }

    public void setGrp(String grp) {
        this.grp = grp;
    }

    public byte[] getMinutes() {
        return minutes;
    }

    public void setMinutes(byte[] minutes) {
        this.minutes = minutes;
    }

    public String getIdentifier() {
        return identifier;
    }

    public void setIdentifier(String identifier) {
        this.identifier = identifier;
    }

    @XmlTransient
    public Collection<Degreeprogram> getDegreeprogramCollection() {
        return degreeprogramCollection;
    }

    public void setDegreeprogramCollection(Collection<Degreeprogram> degreeprogramCollection) {
        this.degreeprogramCollection = degreeprogramCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (identifier != null ? identifier.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Minute)) {
            return false;
        }
        Minute other = (Minute) object;
        if ((this.identifier == null && other.identifier != null) || (this.identifier != null && !this.identifier.equals(other.identifier))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "cse308.entities.Minute[ identifier=" + identifier + " ]";
    }
     @Override
    public List<List<GeneralEntity>> getAssociatedClasses() {
        List<List<GeneralEntity>> l = new ArrayList<List<GeneralEntity>>();
        l.add((List)this.degreeprogramCollection);
        return l;
    }

    @Override
    public List<GeneralEntity> getAssociatedClass(String associated) {
        if(associated.equals(Degreeprogram.class.getSimpleName())){
            return (List)this.degreeprogramCollection;
        }
        return null;
    }

    @Override
    public void setWithClass(GeneralTest gt) {
        if(gt instanceof MinuteClass){
            MinuteClass mc = (MinuteClass)gt;
            date=mc.getDate();
            this.grp=mc.getGrp();
        }
    }

    @Override
    public void testAddClass(GeneralEntity ge) {
    }

    @Override
    public void removeClass(GeneralEntity ge) {
    }

    @Override
    public String getIdentifier2() {
        return this.identifier;
    }

    @Override
    public GeneralEntity findCorrespondingEntity() {
        return this;
    }

    @Override
    public boolean equalsEntity(GeneralEntity entity) {
        return this.equals(entity);
    }

    @Override
    public Object getPK() {
        return this.identifier;
    }
}
